import {
  defineStore
} from 'pinia'

export const UserStore = defineStore('user', () => {
  const userName = localStorage.getItem('_site_login_username')
  const userId = localStorage.getItem('_site_login_userId')
  const account = localStorage.getItem('_site_login_account')
  const token = localStorage.getItem('_site_token')
  const reminder = localStorage.getItem('_site_reminder')



  const login = (customer) => {
    localStorage.setItem('_site_login_account', customer.account)
    localStorage.setItem('_site_login_username', customer.customerName)
    localStorage.setItem('_site_login_userId', customer.customerId)
    localStorage.setItem('_site_token', customer.token)
    localStorage.setItem('_site_reminder', customer.reminder)
  }

  const logout = () => {
    localStorage.removeItem('_site_token')
  }

  return {
    userName,
    userId,
    account,
    reminder,
    token,
    login,
    logout
  }
})
